package com.galeno.day09.test;

import com.alibaba.fastjson.JSON;
import lombok.*;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.ProcessFunction;
import org.apache.flink.util.Collector;

/**
 * @author galeno
 * @Title:
 * @Description:
 * @date 2021/10/2620:02
 */
public class NoneKeyedPorcessFunction {
    @Data@NoArgsConstructor@AllArgsConstructor
    public static class User{
        private String name;
        private int age;
        private double fv;

    }
    public static void main(String[] args) throws Exception {
       // User u1q = new User("张三", 15, 1.5);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStreamSource<String> lines = env.socketTextStream("192.168.77.3", 9999);
        SingleOutputStreamOperator<User> process = lines.process(new ProcessFunction<String, User>() {
            @Override
            public void processElement(String value, Context ctx, Collector<User> out) throws Exception {
                try {
                    User user = JSON.parseObject(value, User.class);
                    out.collect(user);
                } catch (Exception e) {
                    e.printStackTrace();

                } finally {
                    System.out.println("卢本伟牛逼");
                }
            }
        });
        process.print();
        env.execute();


    }
}
